package org.eiahe.hr.employeeRelation.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import org.ehe.common.core.BaseController;
import org.ehe.common.core.domain.R;
import org.ehe.common.core.validate.AddGroup;
import org.ehe.common.core.validate.EditGroup;
import org.ehe.common.log.annotation.Log;
import org.ehe.common.log.enums.BusinessType;
import org.ehe.common.mybatis.core.page.PageQuery;
import org.ehe.common.mybatis.core.page.TableDataInfo;
import org.eiahe.hr.employeeRelation.domain.bo.RewardPunishmentApplicationBo;
import org.eiahe.hr.employeeRelation.domain.bo.RewardPunishmentRecordBo;
import org.eiahe.hr.employeeRelation.domain.vo.RewardPunishmentApplicationVo;
import org.eiahe.hr.employeeRelation.domain.vo.RewardPunishmentRecordVo;
import org.eiahe.hr.employeeRelation.service.IRewardPunishmentService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 奖惩管理控制器
 *
 * @author zhangnn
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/employeeRelation/rewardPunishment")
public class RewardPunishmentController extends BaseController {

    private final IRewardPunishmentService rewardPunishmentService;

    /**
     * 查询奖惩申请列表
     */
    @SaCheckPermission("employeeRelation:rewardPunishment:list")
    @GetMapping("/application/list")
    public TableDataInfo<RewardPunishmentApplicationVo> listApplication(RewardPunishmentApplicationBo bo,
            PageQuery pageQuery) {
        // 实际实现中需要构建查询条件
        return TableDataInfo.build(rewardPunishmentService.selectRewardPunishmentApplicationList(bo));
    }

    /**
     * 获取奖惩申请详细信息
     */
    @SaCheckPermission("employeeRelation:rewardPunishment:query")
    @GetMapping(value = "/application/{applicationId}")
    public R<RewardPunishmentApplicationVo> getApplicationInfo(@PathVariable("applicationId") Long applicationId) {
        return R.ok(rewardPunishmentService.selectRewardPunishmentApplicationById(applicationId));
    }

    /**
     * 新增奖惩申请
     */
    @SaCheckPermission("employeeRelation:rewardPunishment:add")
    @Log(title = "奖惩申请", businessType = BusinessType.INSERT)
    @PostMapping("/application")
    public R<Void> addApplication(@Validated(AddGroup.class) @RequestBody RewardPunishmentApplicationBo bo) {
        return toAjax(rewardPunishmentService.insertRewardPunishmentApplication(bo));
    }

    /**
     * 修改奖惩申请
     */
    @SaCheckPermission("employeeRelation:rewardPunishment:edit")
    @Log(title = "奖惩申请", businessType = BusinessType.UPDATE)
    @PutMapping("/application")
    public R<Void> editApplication(@Validated(EditGroup.class) @RequestBody RewardPunishmentApplicationBo bo) {
        return toAjax(rewardPunishmentService.updateRewardPunishmentApplication(bo));
    }

    /**
     * 删除奖惩申请
     */
    @SaCheckPermission("employeeRelation:rewardPunishment:remove")
    @Log(title = "奖惩申请", businessType = BusinessType.DELETE)
    @DeleteMapping("/application/{applicationIds}")
    public R<Void> removeApplication(@PathVariable Long[] applicationIds) {
        return toAjax(rewardPunishmentService.deleteRewardPunishmentApplicationByIds(applicationIds));
    }

    /**
     * 查询奖惩记录列表
     */
    @SaCheckPermission("employeeRelation:rewardPunishment:list")
    @GetMapping("/record/list")
    public TableDataInfo<RewardPunishmentRecordVo> listRecord(RewardPunishmentRecordBo bo, PageQuery pageQuery) {
        // 实际实现中需要构建查询条件
        return TableDataInfo.build(rewardPunishmentService.selectRewardPunishmentRecordList(bo));
    }

    /**
     * 获取奖惩记录详细信息
     */
    @SaCheckPermission("employeeRelation:rewardPunishment:query")
    @GetMapping(value = "/record/{recordId}")
    public R<RewardPunishmentRecordVo> getRecordInfo(@PathVariable("recordId") Long recordId) {
        return R.ok(rewardPunishmentService.selectRewardPunishmentRecordById(recordId));
    }

    /**
     * 新增奖惩记录
     */
    @SaCheckPermission("employeeRelation:rewardPunishment:add")
    @Log(title = "奖惩记录", businessType = BusinessType.INSERT)
    @PostMapping("/record")
    public R<Void> addRecord(@Validated(AddGroup.class) @RequestBody RewardPunishmentRecordBo bo) {
        return toAjax(rewardPunishmentService.insertRewardPunishmentRecord(bo));
    }

    /**
     * 修改奖惩记录
     */
    @SaCheckPermission("employeeRelation:rewardPunishment:edit")
    @Log(title = "奖惩记录", businessType = BusinessType.UPDATE)
    @PutMapping("/record")
    public R<Void> editRecord(@Validated(EditGroup.class) @RequestBody RewardPunishmentRecordBo bo) {
        return toAjax(rewardPunishmentService.updateRewardPunishmentRecord(bo));
    }

    /**
     * 删除奖惩记录
     */
    @SaCheckPermission("employeeRelation:rewardPunishment:remove")
    @Log(title = "奖惩记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/record/{recordIds}")
    public R<Void> removeRecord(@PathVariable Long[] recordIds) {
        return toAjax(rewardPunishmentService.deleteRewardPunishmentRecordByIds(recordIds));
    }

    /**
     * 奖惩审批通过：写入审批信息并补齐记录字段
     */
    @SaCheckPermission("employeeRelation:rewardPunishment:approve")
    @Log(title = "奖惩审批通过", businessType = BusinessType.UPDATE)
    @PostMapping("/application/approve")
    public R<Void> approve(@Validated @RequestBody RewardPunishmentApplicationBo bo) {
        return toAjax(rewardPunishmentService.approveRewardPunishment(bo));
    }

    /**
     * 审批拒绝
     * @param bo
     * @return
     */
    @SaCheckPermission("employeeRelation:rewardPunishment:approve")
    @Log(title = "奖惩审批通过", businessType = BusinessType.UPDATE)
    @PostMapping("/application/reject")
    public R<Void> reject(@Validated @RequestBody RewardPunishmentApplicationBo bo) {
        return toAjax(rewardPunishmentService.rejectRewardPunishment(bo));
    }

}
